//AUTHORS: CANTÓ, J.; BARAIBAR, J. & ARREGUI, J.; CONTACT joel.canto@upf.edu // javier.arregui@upf.edu for inquiries.

// Set Working Directory:

cd "C:\Users\u151889\Desktop\Citizenship & Funds Paper\data"

// Import data:

clear all
use "C:\Users\u151889\Desktop\Citizenship & Funds Paper\data\DATA.dta"

//Recoding region from names to categorical

encode region, gen(region_i)

//Calculating Age2

gen age_2 = (age^2)

// Recode education for our model (still studying with tertiary education together))

recode education 4=3, gen(education_rec)
tab education_rec

//Check for multicollinearity

regress membership gender age age_2 i.economic_crisis_realgdp##i.occupation_rec c.gdppercapita_real c.esif_percapita c.reg_european_identity c.reg_trust_EU c.reg_trust_gvt  i.education_rec  ib4.region_i i.year
vif 
corr  membership age age_2 occupation_rec gdppercapita_real esif_percapita reg_european_identity reg_trust_EU reg_trust_gvt heard_EC education

corr reg_european_identity reg_trust_gvt heard_EC

// Logaritmic transformation of variables for robustness checks in the Appendices
gen agelog = ln(age)
gen age2log = ln(age_2)
gen esiflog = ln(esif_percapita)
gen europeanidentity = ln(reg_european_identity)
gen trustgvt = ln(reg_trust_gvt)
gen heardec = ln(heard_EC)
gen gdplog = ln(gdppercapita_real)


////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// MAIN TEXT REGRESSIONS //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

//1) TABLE 1. Ordinal Logit F.E. (Robust S.E.) 

ologit  membership gender age age_2 i.economic_crisis_realgdp i.occupation_rec c.gdppercapita_real##c.esif_percapita c.reg_european_identity c.heard_EC c.reg_trust_gvt  i.education_rec ib4.region_i i.year, vce(robust) 
eststo model1

// Plot Expected Probabilities of Logistic Regression Coefficients:

* Interaction between ESIF & GDP p.c. (Good Thing):

margins, at (esif_percapita=(0(50)250) gdppercapita_real=(12000(5000)30000)) pr(out(3)) 
marginsplot

margins, at (esif_percapita=(0(50)250)) pr (out(3)) 
marginsplot

* Interaction between ESIF & GDP p.c. (Bad Thing):

margins, at (esif_percapita=(1(100)300) gdppercapita_real=(10500(6000)30000)) pr (out(1))
marginsplot

* Economic crisis (good thing):

margins, at (economic_crisis_realgdp=(0 1)) pr (out(3))
marginsplot

* Economic crisis (bad thing):

margins, at (economic_crisis_realgdp=(0 1)) pr (out(1))
marginsplot

* European Identity

margins, at (reg_european_identity=(1(0.5)3))
marginsplot

* GDP p.c.:

margins, at (gdppercapita_real=(10000(5000)30000))
marginsplot 

* Heard EC:

margins, at (heard_EC=(0(0.5)1))
marginsplot

*2)  TABLE 1. Multilevel Model
 
meologit membership gender age age_2 i.economic_crisis_realgdp i.occupation_rec c.gdppercapita_real##c.esif_percapita c.reg_european_identity c.heard_EC c.reg_trust_gvt  i.education_rec i.year || region: 

////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// APPENDICES REGRESSIONS //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

//Table A3. Ordinal Logistic Regression with Robust Standard Errors (logs) 

ologit  membership gender agelog age2log i.economic_crisis_realgdp i.occupation_rec c.gdplog##c.esiflog c.europeanidentity c.heardec c.trustgvt  i.education_rec ib4.region_i i.year, vce(robust) 

//Tables A4 & A5. Multinomial Logistic Regression with Robust Standard Errors

mlogit  membership gender age age_2 i.economic_crisis_realgdp i.occupation_rec c.gdppercapita_real##c.esif_percapita c.reg_european_identity c.heard_EC c.reg_trust_gvt  i.education_rec ib4.region_i i.year, vce(robust) 
